package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    void insert(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(id) from orders where status=#{status}")
    Integer statistics(Integer status);

    @Select("select * from orders where id=#{id}")
    Orders getById(Integer id);

   @Select("select * from orders where status=#{status} and order_time<#{deadLineTime}")
   List<Orders> selectByStatusAndDeadLineTime(Integer status, LocalDateTime deadLineTime);

    @Select("select sum(amount) from orders where order_time>=#{begin} and order_time<=#{end} and status=#{status}")
    Double sumByMap(Map map);

    Integer getCount(Map map);

    @Select("select order_detail.name, sum(order_detail.number) number from order_detail, orders where order_id = orders.id and order_time BETWEEN #{beginTime} AND #{endTime} and status = 5 group by order_detail.name order by number desc limit 0,10;") List<GoodsSalesDTO>
    top10(LocalDateTime beginTime, LocalDateTime endTime);
}
